package xhwl.insurance.ui.fragment;

import android.content.ClipboardManager;
import android.content.Context;
import android.content.Intent;
import android.os.Bundle;
import android.support.annotation.Nullable;
import android.support.v7.widget.GridLayoutManager;
import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.support.v7.widget.StaggeredGridLayoutManager;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.AdapterView;
import android.widget.ImageView;
import android.widget.LinearLayout;
import android.widget.RadioGroup;
import android.widget.RelativeLayout;
import android.widget.TextView;

import com.umeng.socialize.ShareAction;
import com.umeng.socialize.UMShareListener;
import com.umeng.socialize.bean.SHARE_MEDIA;
import com.umeng.socialize.media.UMImage;

import java.util.ArrayList;

import xhwl.android.common.util.SPUtil;
import xhwl.android.common.util.StringUtil;
import xhwl.android.common.util.ToastUtil;
import xhwl.insurance.R;
import xhwl.insurance.adapter.ExpertAdapter;
import xhwl.insurance.adapter.FindAdapter2;
import xhwl.insurance.adapter.HospitalListAdapter;
import xhwl.insurance.customView.MyGridView;
import xhwl.insurance.customView.PlayerWebView;
import xhwl.insurance.dialog.VideoShareDialog;
import xhwl.insurance.http.api.ClickAmountApi;
import xhwl.insurance.http.api.ExpertListApi;
import xhwl.insurance.http.api.GiveThumbs_upApi;
import xhwl.insurance.http.api.HospitalListApi;
import xhwl.insurance.http.api.VideoListApi;
import xhwl.insurance.http.bean.resp.ExpertResp;
import xhwl.insurance.http.bean.resp.HospitalListResp;
import xhwl.insurance.http.bean.resp.VideoListResp;
import xhwl.insurance.http.bean.resp2.HttpResp;
import xhwl.insurance.ui.DoctorDetailsActivity;
import xhwl.insurance.ui.FindDetailsActivity;
import xhwl.insurance.ui.HospitalDetailsActivity;
import xhwl.insurance.ui.SearchActivity;
import xhwl.insurance.util.XHLog;
import xhwl.insurance.view.MyItemDecoration;
import xhwl.pulltorefresh.PullToRefreshRecyclerView;
import xhwl.pulltorefresh.callback.PullToRefreshListener;
import xhwl.retrofitrx.HttpException;
import xhwl.retrofitrx.HttpManager;
import xhwl.retrofitrx.OnNextListener;


/**
 * Created by fuyi on 2017/9/26.
 */

public class FindFragment2 extends BaseFragment implements PullToRefreshListener, View.OnClickListener {

    private PullToRefreshRecyclerView recyclerView, recyclerView_hospitallist, mRecyclerView_GridView;
    int mPage = 1;

    private FindAdapter2 adapter;
    private ArrayList<VideoListResp> mList = new ArrayList<>();
    private ArrayList<HospitalListResp> mHospitalList = new ArrayList<>();
    private ArrayList<ExpertResp> mExpertList = new ArrayList<>();
    private VideoShareDialog shareDialog;
    private LinearLayout ll_hospitallist, ll_videolist, ll_expertlist;
    private HospitalListAdapter mHospitalListAdapter;
    private ExpertAdapter mExpertAdapter;


    @Nullable
    @Override
    public View onCreateView(LayoutInflater inflater, @Nullable ViewGroup container, @Nullable Bundle savedInstanceState) {
        View view = inflater.inflate(R.layout.fragment_find2, null);
        return view;
    }

    @Override
    protected void initView(View view) {
        initTitleViews(view);
        recyclerView = (PullToRefreshRecyclerView) view.findViewById(R.id.recyclerView);
        recyclerView_hospitallist = (PullToRefreshRecyclerView) view.findViewById(R.id.recyclerView_hospitallist);
        mRecyclerView_GridView = (PullToRefreshRecyclerView) view.findViewById(R.id.rv_gridview_hl);
        ll_hospitallist = (LinearLayout) view.findViewById(R.id.hospitallist);
        ll_videolist = (LinearLayout) view.findViewById(R.id.videolist);
        ll_expertlist = (LinearLayout) view.findViewById(R.id.expertlist);
        initRecylerView();


        adapter = new FindAdapter2(mActivity, mList);
        recyclerView.setAdapter(adapter);

        initRecylerViewGridView();
        initRecylerViewHospital();


    }

    private void initRecylerView() {
        //添加HeaderView
        View headView = View.inflate(mActivity, R.layout.layout_find_head, null);
        RelativeLayout mSearch = (RelativeLayout) headView.findViewById(R.id.rl_search_find);
        TextView mTv_search = (TextView) headView.findViewById(R.id.tv_search_finds);

        mSearch.setOnClickListener(new View.OnClickListener() {
            @Override
            public void onClick(View v) {
                Intent intent = new Intent();
                intent.setClass(mActivity, SearchActivity.class);
                startActivity(intent);
            }
        });
        recyclerView.addHeaderView(headView);
        //设置EmptyView
        View emptyView = View.inflate(mActivity, R.layout.layout_empty_view, null);
        emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        recyclerView.setEmptyView(emptyView);

        final LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView.setLayoutManager(layoutManager);

        recyclerView.addOnScrollListener(new RecyclerView.OnScrollListener() {
            @Override
            public void onScrolled(RecyclerView recyclerView, int dx, int dy) {
                super.onScrolled(recyclerView, dx, dy);
                if (adapter.isPlaying()) {
                    int playingIndex = adapter.getPlayingIndex();

                    int first = layoutManager.findFirstVisibleItemPosition();
                    int last = layoutManager.findLastVisibleItemPosition();
                    XHLog.e("playindex=" + playingIndex + " first=" + first + " last=" + last);
                    if (first == playingIndex + 1 || last == playingIndex - 1) {
                        //此时正在播放的item被完全移出屏幕，暂停播放
                        adapter.pauseCurrentVideo();
                    }
                }

            }
        });
        //设置是否开启上拉加载
        recyclerView.setLoadingMoreEnabled(true);
        //设置是否开启下拉刷新
        recyclerView.setPullRefreshEnabled(true);
        //设置是否显示上次刷新的时间
        recyclerView.displayLastRefreshTime(false);
//        recyclerView.setRefreshLimitHeight(DimenUtil.dip2px(mActivity,50));
    }


    @Override
    protected void setUpTitleView() {
        leftTextView.setVisibility(View.VISIBLE);
        rightTextView.setVisibility(View.VISIBLE);
        leftTextView.setText("视频");
        titleTextView.setText("专家");
        rightTextView.setText("医院");
        RelativeLayout.LayoutParams params = new RelativeLayout.LayoutParams(
                RelativeLayout.LayoutParams.WRAP_CONTENT, RelativeLayout.LayoutParams.WRAP_CONTENT);
        params.setMargins(40,35,0,0);
        leftTextView.setLayoutParams(params);
        leftTextView.setTextSize(18);
        titleTextView.setTextSize(17);
        rightTextView.setTextSize(16);

        backImageView.setVisibility(View.GONE);

        titleTextView.setOnClickListener(this);
        rightTextView.setOnClickListener(this);
        leftTextView.setOnClickListener(this);
    }


    @Override
    public void onClick(View view) {
        switch (view.getId()) {
            case R.id.title_left_textview://视频
                ll_videolist.setVisibility(View.VISIBLE);
                ll_hospitallist.setVisibility(View.GONE);
                ll_expertlist.setVisibility(View.GONE);
                leftTextView.setTextSize(18);
                titleTextView.setTextSize(16);
                rightTextView.setTextSize(15);
                break;

            case R.id.title_textview://专家
                ll_videolist.setVisibility(View.GONE);
                ll_hospitallist.setVisibility(View.GONE);
                ll_expertlist.setVisibility(View.VISIBLE);
                leftTextView.setTextSize(15);
                titleTextView.setTextSize(18);
                rightTextView.setTextSize(15);

                break;
            case R.id.title_right_textview://医院
                ll_videolist.setVisibility(View.GONE);
                ll_hospitallist.setVisibility(View.VISIBLE);
                ll_expertlist.setVisibility(View.GONE);
                leftTextView.setTextSize(15);
                titleTextView.setTextSize(16);
                rightTextView.setTextSize(18);

                break;
        }
    }


    private void initRecylerViewGridView() {
        //设置EmptyView
        View emptyView = View.inflate(mActivity, R.layout.layout_empty_view, null);
        emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        mRecyclerView_GridView.setEmptyView(emptyView);
        mRecyclerView_GridView.setLayoutManager(new GridLayoutManager(mActivity, 3,
                LinearLayoutManager.VERTICAL, false));
        //设置分隔线
//        mRecyclerView_GridView.addItemDecoration(new MyItemDecoration(mActivity));
        mRecyclerView_GridView.addItemDecoration(new MyItemDecoration(1, getResources().getColor(R.color.main_tab_text_normal)));

        //设置是否开启上拉加载
        mRecyclerView_GridView.setLoadingMoreEnabled(true);
        //设置是否开启下拉刷新
        mRecyclerView_GridView.setPullRefreshEnabled(true);
        //设置是否显示上次刷新的时间
        mRecyclerView_GridView.displayLastRefreshTime(false);


        mExpertAdapter = new ExpertAdapter(getActivity(), mExpertList);
        mRecyclerView_GridView.setAdapter(mExpertAdapter);

        mExpertAdapter.setOnItemClickLitener(new ExpertAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(View view, int position) {

                startActivity(new Intent(getActivity(), DoctorDetailsActivity.class)
                        .putExtra("EXPERT_RANK", mExpertList.get(position).getEXPERT_RANK())
                        .putExtra("EXPERT_NAME", mExpertList.get(position).getEXPERT_NAME())
                        .putExtra("EXPERT_SKILL", mExpertList.get(position).getEXPERT_SKILL())
                        .putExtra("HOS_NAME", mExpertList.get(position).getHOS_NAME())
                        .putExtra("HOS_ADDRESS", mExpertList.get(position).getHOS_ADDRESS())
                        .putExtra("EXPERT_DESC", mExpertList.get(position).getEXPERT_DESC())
                        .putExtra("DEP_NAME", mExpertList.get(position).getDEP_NAME())
                        .putExtra("SMALL_PIC", mExpertList.get(position).getSMALL_PIC())
                        .putExtra("EXPERT_ROLE", mExpertList.get(position).getEXPERT_ROLE())
                        .putExtra("EXPERT_ID", mExpertList.get(position).getEXPERT_ID()));
            }
        });
    }

    private void initRecylerViewHospital() {
        //设置EmptyView
        View emptyView = View.inflate(mActivity, R.layout.layout_empty_view, null);
        emptyView.setLayoutParams(new ViewGroup.LayoutParams(ViewGroup.LayoutParams.MATCH_PARENT,
                ViewGroup.LayoutParams.MATCH_PARENT));
        recyclerView_hospitallist.setEmptyView(emptyView);

        final LinearLayoutManager layoutManager = new LinearLayoutManager(mActivity);
        layoutManager.setOrientation(LinearLayoutManager.VERTICAL);
        recyclerView_hospitallist.setLayoutManager(layoutManager);

        //设置是否开启上拉加载
        recyclerView_hospitallist.setLoadingMoreEnabled(true);
        //设置是否开启下拉刷新
        recyclerView_hospitallist.setPullRefreshEnabled(true);
        //设置是否显示上次刷新的时间
        recyclerView_hospitallist.displayLastRefreshTime(false);


        mHospitalListAdapter = new HospitalListAdapter(mActivity, mHospitalList);
        recyclerView_hospitallist.setAdapter(mHospitalListAdapter);
        mHospitalListAdapter.setOnItemClickLitener(new HospitalListAdapter.OnItemClickLitener() {
            @Override
            public void onItemClick(int position) {
                Intent intent = new Intent(mActivity, HospitalDetailsActivity.class);
//                Bundle bundle = new Bundle();
//                bundle.putParcelableArrayList("hospitaldetails", mHospitalList);
//                intent.putExtras(bundle);
                intent.putExtra("HOS_NAME", mHospitalList.get(position-1).getHOS_NAME());
                intent.putExtra("HOS_PIC", mHospitalList.get(position-1).getHOS_PIC());
                intent.putExtra("DISTRICT_NAME", mHospitalList.get(position-1).getDISTRICT_NAME());
                intent.putExtra("HOS_ADDRESS", mHospitalList.get(position-1).getHOS_ADDRESS());
                intent.putExtra("HOS_DESC", mHospitalList.get(position-1).getHOS_DESC());
                intent.putExtra("LEVEL_NAME", mHospitalList.get(position-1).getLEVEL_NAME());
                intent.putExtra("HOS_XZ", mHospitalList.get(position-1).getHOS_XZ());
                intent.putExtra("TYPE_NAME", mHospitalList.get(position-1).getTYPE_NAME());
                intent.putExtra("HOS_ID", mHospitalList.get(position-1).getHOS_ID());
                startActivity(intent);

            }
        });

    }


    @Override
    protected void initListener() {

        //设置刷新回调
        recyclerView.setPullToRefreshListener(this);
        recyclerView_hospitallist.setPullToRefreshListener(this);
        mRecyclerView_GridView.setPullToRefreshListener(this);

        adapter.setOnItemClickLitener(new FindAdapter2.OnItemClickLitener() {
            @Override
            public void onItemClick(int position) {
                //视频详情界面，
                startActivity(new Intent(getActivity(), FindDetailsActivity.class)
                        .putExtra("VIDEO_ID", mList.get(position - 1).getVIDEO_ID())
                        .putExtra("VIDEO_NAME", mList.get(position - 1).getVIDEO_NAME())
                );
            }

            @Override//视频点击量
            public void onClickAmount(int position) {
                ClickAmountApi api = new ClickAmountApi(mList.get(position - 1).getVIDEO_ID());
                HttpManager.getInstance().dealHttp(FindFragment2.this, api, new OnNextListener<HttpResp>() {
                    @Override
                    public void onNext(HttpResp resp) {
                        if (resp.isOk()) {
                            xhwl.android.common.log.XHLog.e("视频点击量成功：" + resp.message);
                        } else {
                            xhwl.android.common.log.XHLog.e("视频点击量失败：" + resp.message);
                        }
                    }

                    @Override
                    public void onError(HttpException ex) {
                        super.onError(ex);
                    }
                });

            }

            @Override
            public void onGoodClick(final int position, final ImageView imageview, final TextView textview) {
                String member_id = SPUtil.getPersonInfoSp().getString(SPUtil.SPPersonInfo.MEMBER_ID, "");
                GiveThumbs_upApi api = new GiveThumbs_upApi(mList.get(position - 1).getVIDEO_ID(), member_id);
                HttpManager.getInstance().dealHttp(FindFragment2.this, api, new OnNextListener<HttpResp>() {
                    @Override
                    public void onNext(HttpResp resp) {
                        if (resp.isOk()) {
                            mList.get(position - 1).isSelected = !mList.get(position - 1).isSelected;
                            int thumbs = Integer.valueOf(mList.get(position - 1).getTHUMBS_UP()).intValue();
                            int thubs2 = thumbs += 1;
                            int thubs3 = thumbs -= 1;
//
                            if (mList.get(position - 1).getTHUMBS_FLAG().equals("1")) {
                                int thubs4 = thumbs -= 1;
                                int thubs5 = thumbs += 1;
                                imageview.setImageResource(mList.get(position - 1).isSelected ? R.drawable.icon_thumbs_up : R.drawable.icon_thumbs_up2);
                                textview.setText(mList.get(position - 1).isSelected ? thubs4 + "" : thubs5 + "");
//                                ToastUtil.showToast(mActivity,mList.get(position - 1).isSelected ? "取消点赞":"点赞成功");
                            } else {
                                imageview.setImageResource(mList.get(position - 1).isSelected ? R.drawable.icon_thumbs_up2 : R.drawable.icon_thumbs_up);
                                textview.setText(mList.get(position - 1).isSelected ? thubs2 + "" : thubs3 + "");
//                                ToastUtil.showToast(mActivity,mList.get(position - 1).isSelected ? "点赞成功":"取消点赞");
                            }
                        } else {
                            ToastUtil.showToast(mActivity, resp.message);
                        }

                    }

                    @Override
                    public void onError(HttpException ex) {
                        super.onError(ex);
                    }
                });
            }


            @Override
            public void onShareClick(final int position, final PlayerWebView videoPlay) {
                shareDialog = new VideoShareDialog(mActivity);
                shareDialog.setCancelable(false);
                shareDialog.setCanceledOnTouchOutside(false);
                View dialog = View.inflate(mActivity, R.layout.dialog_videoshare, null);
                RelativeLayout mWxCircle = (RelativeLayout) dialog.findViewById(R.id.rl_wxcircle);
                RelativeLayout mWechat = (RelativeLayout) dialog.findViewById(R.id.rl_wechat);
                RelativeLayout mCopy = (RelativeLayout) dialog.findViewById(R.id.rl_copy);
                TextView mCancel = (TextView) dialog.findViewById(R.id.btn_videocancel);
                shareDialog.setContentView(dialog);
                shareDialog.show();
                videoPlay.Suspend();
                final UMImage image = new UMImage(mActivity, mList.get(position - 1).getVIDEO_PIC());
                mWxCircle.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        new ShareAction(mActivity)
                                .setPlatform(SHARE_MEDIA.WEIXIN_CIRCLE)
                                .setCallback(shareListener)
                                .withTitle(mList.get(position - 1).getVIDEO_NAME())
                                .withTargetUrl(mList.get(position - 1).getVIDEO_URL())
                                .withText(mList.get(position - 1).getVIDEO_URL())
                                .withMedia(image)
                                .share();

                    }
                });

                mWechat.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        new ShareAction(mActivity)
                                .setPlatform(SHARE_MEDIA.WEIXIN)
                                .setCallback(shareListener)
                                .withTitle(mList.get(position - 1).getVIDEO_NAME())
                                .withTargetUrl(mList.get(position - 1).getVIDEO_URL())
                                .withText(mList.get(position - 1).getVIDEO_URL())
                                .withMedia(image)
                                .share();
                    }
                });

                mCopy.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        if (!StringUtil.isEmpty(mList.get(position - 1).getVIDEO_URL())) {
                            ClipboardManager cmb = (ClipboardManager) mActivity.getSystemService(Context.CLIPBOARD_SERVICE);
                            cmb.setText(mList.get(position - 1).getVIDEO_URL());
                            ToastUtil.showToast(mActivity, "链接已复制");
                        } else {
                            ToastUtil.showToast(mActivity, "该视频没有链接");
                        }

                    }
                });
                mCancel.setOnClickListener(new View.OnClickListener() {
                    @Override
                    public void onClick(View view) {
                        shareDialog.dismiss();
                    }
                });
            }
        });

    }

    @Override
    public void onResume() {
        super.onResume();
        loadData();
    }

    @Override
    protected void loadData() {
        getData(1, "");
        getHospitalList(1);
        getExpertlList(1);
//        recyclerView.onRefresh();
    }

    @Override
    public void onRefresh() {
        getData(1, "");
        getHospitalList(1);
        getExpertlList(1);
    }

    @Override
    public void onLoadMore() {
        getData(mPage + 1, "");
        getHospitalList(mPage + 1);
        getExpertlList(mPage + 1);
    }

    protected void getExpertlList(final int page_num) {
        String expert_name = "";
        ExpertListApi api = new ExpertListApi(expert_name, page_num);
        HttpManager.getInstance().dealHttp(this, api, new OnNextListener<ArrayList<ExpertResp>>() {
            @Override
            public void onNext(ArrayList<ExpertResp> resp) {
                if (page_num == 1) { //下拉刷新操作
                    if (resp != null && resp.size() > 0) {
                        mRecyclerView_GridView.setRefreshComplete();
                        mExpertList.addAll(resp);
                        mExpertAdapter.notifyDataSetChanged();
                    } else {
                        mRecyclerView_GridView.setRefreshFail();
                    }
                } else {
                    if (resp != null) {
                        mRecyclerView_GridView.setLoadMoreComplete();
                        if (resp != null && resp.size() > 0) {
                            mPage = page_num;
                            mExpertList.addAll(resp);
                            mExpertAdapter.notifyDataSetChanged();
                        } else {
                            ToastUtil.showToast(mActivity, getString(R.string.no_more_data));
                        }
                    } else {
                        mRecyclerView_GridView.setLoadMoreFail();
                    }
                }

            }

            @Override
            public void onError(HttpException ex) {
                super.onError(ex);
                if (page_num == 1) {
                    mRecyclerView_GridView.setRefreshFail();
                } else {
                    mRecyclerView_GridView.setLoadMoreFail();
                }
            }
        });

    }

    protected void getHospitalList(final int page_num) {
        String hos_name = "";
        HospitalListApi api = new HospitalListApi(hos_name, page_num);
        HttpManager.getInstance().dealHttp(this, api, new OnNextListener<ArrayList<HospitalListResp>>() {
            @Override
            public void onNext(ArrayList<HospitalListResp> resp) {
                if (page_num == 1) { //下拉刷新操作
                    if (resp != null && resp.size() > 0) {
                        recyclerView_hospitallist.setRefreshComplete();
                        mHospitalList.addAll(resp);
                        mHospitalListAdapter.notifyDataSetChanged();
                    } else {
                        recyclerView_hospitallist.setRefreshFail();
                    }
                } else {
                    if (resp != null) {
                        recyclerView_hospitallist.setLoadMoreComplete();
                        if (resp != null && resp.size() > 0) {
                            mPage = page_num;
                            mHospitalList.addAll(resp);
                            mHospitalListAdapter.notifyDataSetChanged();
                        } else {
                            ToastUtil.showToast(mActivity, getString(R.string.no_more_data));
                        }
                    } else {
                        recyclerView_hospitallist.setLoadMoreFail();
                    }
                }

            }

            @Override
            public void onError(HttpException ex) {
                super.onError(ex);
                if (page_num == 1) {
                    recyclerView_hospitallist.setRefreshFail();

                } else {
                    recyclerView_hospitallist.setLoadMoreFail();
                }
            }
        });


    }

    private void getData(final int page, String SearchText) {
        String member_id = SPUtil.getPersonInfoSp().getString(SPUtil.SPPersonInfo.MEMBER_ID, "");
        VideoListApi api = new VideoListApi(member_id, SearchText, page);
        HttpManager.getInstance().dealHttp(this, api, new OnNextListener<HttpResp<ArrayList<VideoListResp>>>() {
            @Override
            public void onNext(HttpResp<ArrayList<VideoListResp>> resp) {
                if (page == 1) { //下拉刷新操作
                    if (resp != null) {
                        recyclerView.setRefreshComplete();
                        if (resp.isOk()) {
                            mPage = 1;
                            mList.clear();
                            if (resp.data != null && resp.data.size() > 0) {
                                mList.addAll(resp.data);
                            }
                            adapter.notifyDataSetChanged();
                        } else {
                            ToastUtil.showToast(mActivity, resp.message);
                        }
                    } else {
                        recyclerView.setRefreshFail();
                    }
                } else {
                    if (resp != null) {
                        recyclerView.setLoadMoreComplete();
                        if (resp.isOk()) {
                            if (resp.data != null && resp.data.size() > 0) {
                                mPage = page;
                                mList.addAll(resp.data);
                                adapter.notifyDataSetChanged();
                            } else {
                                ToastUtil.showToast(mActivity, getString(R.string.no_more_data));
                            }
                        } else {
                            ToastUtil.showToast(mActivity, resp.message);
                        }
                    } else {
                        recyclerView.setLoadMoreFail();
                    }
                }
            }

            @Override
            public void onError(HttpException ex) {
                super.onError(ex);
                if (page == 1) {
                    recyclerView.setRefreshFail();
                } else {
                    recyclerView.setLoadMoreFail();
                }
            }
        });

    }

    @Override
    public void onPause() {
        super.onPause();
        adapter.pauseCurrentVideo();
    }

    private UMShareListener shareListener = new UMShareListener() {

        /**
         * @descrption 分享成功的回调
         * @param platform 平台类型
         */
        @Override
        public void onResult(SHARE_MEDIA platform) {
            ToastUtil.showToast(mActivity, "分享成功！");
            if (shareDialog != null && shareDialog.isShowing()) {
                shareDialog.dismiss();
            }
        }

        /**
         * @descrption 分享失败的回调
         * @param platform 平台类型
         * @param t 错误原因
         */
        @Override
        public void onError(SHARE_MEDIA platform, Throwable t) {
            ToastUtil.showToast(mActivity, "分享失败！");
        }

        /**
         * @descrption 分享取消的回调
         * @param platform 平台类型
         */
        @Override
        public void onCancel(SHARE_MEDIA platform) {
            ToastUtil.showToast(mActivity, "取消分享");

        }
    };


}
